Модуль:CroqueTest
test functions to auto format some stuff for auto patch hystory generation -- entry has first to be formatted in notepad++ with the following -- ctr H : ^ to " (reg exp enabled : begining of each line start with ") -- ctr H : " to " (removes the tab from begining of lines) -- ctr H : $ to ", (end of line into ",) -- copy and paste here... remove last comma local p = {} local regist1={ "v6"=1,"v7"=1,"v8"=1,"v9"=1,"v10"=1, "v11"=2,"v12"=2,"v13"=2,"v14"=2,"v15"=2,"v15A"=2,"v15B"=2,"v16"=2,"v16A"=2,"v16B"=2, "v17"=2,"v17A"=2,"v17B"=2,"v18"=2,"v18A"=2,"v18B"=2,"v18C"=2, "v19"=2,"v19A"=2,"v19B"=2,"v19C"=2,"v20"=2,"v20A"=2,"v20B"=2, "v21"=3,"v22"=3,"v22A"=3,"v22B"=3,"v22C"=3,"v22D"=3, } local regist2={'Module:CroqueTest/data','Module:CroqueTest/data2','Module:CroqueTest/data3'} local keywords=mw.loadData( 'Module:CroqueTest/keywords' ) function splitter(str,delim) if string.find(str,delim) nil then return { str } end if maxNb nil or maxNb < 1 then maxNb = 0 -- No limit end local result = {} local pat = "(.-)" .. delim .. "()" local nb = 0 local lastPos for part, pos in string.gfind(str, pat) do nb = nb + 1 resultnb = part lastPos = pos if nb maxNb then break end end -- Handle the last field if nb ~= maxNb then result+ 1 = string.sub(str, lastPos) end return result end function p.findall(line,key) --local line="*Fix for %[%Amp%%] Aura stacking. A word from the designer: Rifle Amp, 45% damage buff stacking was too much, reduced to 27% (4.5% base). This was a typo on my part." --local key="Amp" --mw.log(string.find(string.upper(line),string.upper(key))) local result={} local i=0 local j=0 while true do i,j = string.find(string.upper(line),string.upper(key), i+1) if i nil then break end --mw.log(i,j) table.insert(result, {begin=i,zeend=j}) end --for kk,vv in ipairs(result) do for k,v in pairs(vv) do mw.log(key,k,v) end end return result end function p.checkline(line) --local line="*Fix for %[%Amp%%] Aura stacking. A word from the designer: Rifle Amp, 45% damage buff stacking was too much, reduced to 27% (4.5% base). This was a typo on my part." --mw.log(line) --for k,v in ipairs(keywords12) do mw.log(k, v) end local keystring='' for j, key in ipairs(keywords) do local aliases=key1 local antialiases=key2 local indexes={} local aindexes={} for jj, key1 in ipairs(aliases) do --gather all indexes of aliases if(string.find(string.upper(line),string.upper(key1))~=nil) then --local tt={string.find(string.upper(line),string.upper(key1))} --mw.log(key1,tt1,tt2) --table.insert(indexes,tt) local tt=p.findall(line,key1) for k,v in ipairs(tt) do table.insert(indexes,v) end end end -- --for k,v in ipairs(indexes) do mw.log(k, v) end -- for jj, key2 in ipairs(antialiases) do --local antiindex if (string.find(string.upper(line),string.upper(key2))~=nil) then --antiindex={string.find(string.upper(line),string.upper(key2))} --for kk, aliindex in ipairs(indexes) do -- if (aliindex1>=antiindex1 and aliindex1=m and i<=n) then nogood=nogood+1 break end end end --mw.log(good,nogood) if(good>nogood) then keystring=keystring..aliases1..'/' end end --final construction of the string --if(indexes1~=nil) then -- keystring=keystring..aliases1..'/' --end end --mw.log(keystring) return keystring end function p.checktags(line) --local line="*New weapons: Dual Zoren, Akbolto, and Boltor!" --mw.log(line) --for k,v in ipairs(keywords12) do mw.log(k, v) end local keystring='' for j, key in ipairs(keywords) do local aliases=key1 local antialiases=key2 local indexes={} local aindexes={} for jj, key1 in ipairs(aliases) do --gather all indexes of aliases if(string.find(string.upper(line),string.upper(key1))~=nil) then --local tt={string.find(string.upper(line),string.upper(key1))} --mw.log(key1,tt1,tt2) --table.insert(indexes,tt) local tt=p.findall(line,key1) for k,v in ipairs(tt) do table.insert(indexes,v) end end end -- --for k,v in ipairs(indexes) do mw.log(k, v) end -- for jj, key2 in ipairs(antialiases) do --local antiindex if (string.find(string.upper(line),string.upper(key2))~=nil) then local tt=p.findall(line,key2) for k,v in ipairs(tt) do table.insert(aindexes,v) end end end --for kk,vv in ipairs(indexes) do for k,v in pairs(vv) do mw.log(k,v) end end --for kk,vv in ipairs(aindexes) do for k,v in pairs(vv) do mw.log(k,v) end end --Now we cross check everything if(indexes1~=nil and aindexes1 nil) then keystring=keystring..'"'..aliases1..'",' else local nogood=0 local good=0 for kk, ij in ipairs(indexes) do good=good+1 i=ij.begin j=ij.zeend for l, mn in ipairs(aindexes) do m=mn.begin n=mn.zeend --mw.log(i , j , m , n) if (i>=m and i<=n) then nogood=nogood+1 break end end end --mw.log(good,nogood) if(good>nogood) then keystring=keystring..'"'..aliases1..'",' end end end --mw.log(keystring) return keystring end function p.formatBFSold(frame) if(type(UnformattedData)~="table") then return "No Data" end local BFS=UnformattedData[frame.args1] local result='' local nline=0 local tab=' ' if(type(BFS)~="table") then return "No Entries" end for i, line in ipairs(BFS) do if(line "") then result=result--....line..' ' elseif(string.find(line,"Expand")~=nil) then result=result--..' ' elseif(string.find(line,"Forum Post")~=nil) then result=result-- elseif(string.find(line,"Update %d")~=nil or string.find(line,"Update:%s")~=nil or string.find(line,"Hotfix:%s")~=nil or string.find(line,"Hotfix %d")~=nil) then local vers=string.gsub(line,"Update ","") vers=string.gsub(vers,"Hotfix ","") result=result..'}, {"Version"={"'..vers..'"}, ' else local keystring= for j, key in ipairs(keywords) do if(string.find(line,key)~=nil or string.find(line,string.upper(key))~=nil) then keystring=keystring..key..'/' end end nline=nline+1 result=result..tab..tab result=result..'"'..keystring..'"={ ' result=result..tab..tab..tab result=result..'"'..line..'" '..tab..tab'}, ' end end result='Number of lines: '..nline..' '..result -- mw.log(result) return result end function p.formatBFS(frame) local versions=frame.args1 local result='' local nline=0 local tab=' ' local openframe = false local openedframe = '' local UnformattedData={} local BFS ={} if (regist1versions~=nil) then UnformattedData=mw.loadData( regist2[regist1versions] ) if(type(UnformattedData)~="table") then return "No Data" end BFS=UnformattedDataversions if(type(BFS)~="table") then return "No Entries" end else return "Bad Argument" end for i, line in ipairs(BFS) do if(line "") then if (openframe) then result=result..tab..tab..'{tags={""},text={"<%br/>"}}, ' end elseif(string.find(line," ") then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end result=result..' },--update end '-- elseif(string.find(line,"|update number")~=nil) then local vers=string.gsub(line,"|update number.-= ","") vers=string.gsub(vers,"|update number.-=","") result=result..'number"={"'..vers..'"}, ' elseif(string.find(line,"|type")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end local vers=string.gsub(line,"|type.-= ","") vers=string.gsub(vers,"|type.-=","") result=result..'"type"={"'..vers..'"}, ' elseif(string.find(line,"|date")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end local vers=string.gsub(line,"|date.-= ","") vers=string.gsub(vers,"|date.-=","") result=result..'"date"={"'..vers..'"}, ' elseif(string.find(line,"|forumurl ")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end local vers=string.gsub(line,"|forumurl.-= ","") vers=string.gsub(vers,"|forumurl.-=","") result=result..'"forumurl"={"'..vers..'"}, ' elseif(string.find(line,"|title")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end local vers=string.gsub(line,"|title.-= ","") vers=string.gsub(vers,"|title.-=","") result=result..'"title"={"'..vers..'"}, ' elseif(string.find(line,"|image")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end local vers=string.gsub(line,"|image.-= ","") vers=string.gsub(vers,"|image.-=","") result=result..'"image"={"'..vers..'"}, ' elseif(string.find(line,"|misc")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end result=result..'"misc"={ ' openframe=true openedframe = 'misc' elseif(string.find(line,"|additions")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end result=result..'"additions"={ ' openframe=true openedframe = 'additions' elseif(string.find(line,"|changes")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end result=result..'"changes"={ ' openframe=true openedframe = 'changes' elseif(string.find(line,"|fixes")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end result=result..'"fixes"={ ' openframe=true openedframe = 'fixes' elseif(string.find(line,"|conclave")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end result=result..'"conclave"={ ' openframe=true openedframe = 'conclave' elseif(string.find(line,"|localizations")~=nil) then if(openframe) then result=result..'},--'..openedframe..' end ' openframe=false end result=result..'"localizations"={ ' openframe=true openedframe = 'localizations' else local tags=p.checktags(line) nline=nline+1 result=result..tab..tab result=result..'{tags={'..tags..'},text={"'..line..'"}}, ' end end local preamble="local PatchData = { " local postamble=" } return PatchData" result='Number of lines: '..nline..' '..preamble..result..postamble..'' --mw.log(result) return result end return p